package me.kennylee.mobile.sms.code;

import com.google.common.collect.Maps;
import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.Collections;
import java.util.Map;

/**
 * <p> 短信内容 </p>
 * <p>Created on 31/1/2018.</p>
 *
 * @author kennylee
 */
@Data
@RequiredArgsConstructor(staticName = "of")
public class SmsMessage {
    /**
     * 发送手机
     */
    private String rec_num;
    /**
     * 短信签名-可在短信控制台中找到
     */
    private String sign_name;
    /**
     * 给模板发送的参数
     */
    @Setter(AccessLevel.NONE)
    private volatile Map<String, String> param = Collections.unmodifiableMap(Maps.newHashMap());
    /**
     * 短信模板
     */
    private String template;

    public void addParam(String name, String value) {
        Map<String, String> m = getParamMap();
        m.put(name, value);
        setParam(m);
    }

    public void addParams(Map<String, String> params) {
        Map<String, String> m = getParamMap();
        m.putAll(params);
        setParam(m);
    }

    public String removeParam(String name) {
        Map<String, String> m = getParamMap();
        String s = m.remove(name);
        setParam(m);
        return s;
    }

    private Map<String, String> getParamMap() {
        Map<String, String> m = Maps.newHashMap();
        m.putAll(param);
        return m;
    }

    private void setParam(Map<String, String> m) {
        param = Collections.unmodifiableMap(m);
    }
}
